#include <Quantity.h>

#define EPISILON 0.0001

Quantity::Quantity(double value, const Unit &unit): value_m(value), unit_m(unit)
{
}

bool Quantity::operator==(const Quantity &quant)const
{
    if(!unit_m.isSameType(quant.unit_m))
    {
        return false;
    } else {
        double delta = unit_m.toBaseVlaue(value_m) - quant.unit_m.toBaseVlaue(quant.value_m);
        return -EPISILON <= delta && delta <= EPISILON;
    }
}

bool Quantity::operator!=(const Quantity &quant)const
{
    return !(*this == quant);
}

void Quantity::toString(std::ostream & os, const Format &format)
{
    format.toString(os,value_m,unit_m);
}

double Quantity::getSumOfBaseUnit(const Quantity& quant) const
{
    return unit_m.toBaseVlaue(value_m) + quant.unit_m.toBaseVlaue(quant.value_m);
}
